package net.xinqushi.gc;

import java.lang.ref.WeakReference;

public class RefGC {

    public static void main(String[] args) throws InterruptedException {
        WeakReference<RefGC> weakReference = new WeakReference<RefGC>(new RefGC());
        //System.gc();
        //weakReference.get();
        ThreadLocal<WeakReference> local = new ThreadLocal();
        local.set(weakReference);
        weakReference = null;
        System.gc();
        Thread.sleep(1000L);
        System.out.println(local.get());
        //local.set(weakReference);
    }

    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println(this.getClass() +  "  has been finalized ");
    }
}
